package com.myway.controller;

import com.myway.pojo.TabQuestionAnswer;
import com.myway.pojo.TabQuestionType;
import com.myway.service.TabQuestionAnswerService;
import com.myway.service.TabQuestionTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Created by Zap on 2018-08-13.
 */
@Controller
@RequestMapping("en/question")
public class QuestionController {

    @Autowired
    @Qualifier("tabQuestionAnswerServiceImpl")
    private TabQuestionAnswerService tabQuestionAnswerService;

    @Autowired
    @Qualifier("tabQuestionTypeServiceImpl")
    private TabQuestionTypeService tabQuestionTypeService;

    @RequestMapping("/selectQuestionByTypeId")
    public ModelAndView selectQuestionByTypeId(int typeId){
        List<TabQuestionType> qtList = tabQuestionTypeService.selectAll();
        List<TabQuestionAnswer> qaList = tabQuestionAnswerService.selectByTypeId(typeId);
        ModelAndView mv = new ModelAndView();
        mv.addObject("qtList",qtList);
        mv.addObject("qaList",qaList);
        String typeName = "";
        for (TabQuestionType tabQuestionType:qtList) {
            if(tabQuestionType.getId() == typeId){
                typeName = tabQuestionType.getTypeName().replaceAll(" ","");
            }
        }
        System.out.println(typeName);
        mv.setViewName("en/" + typeName);
        return mv;
    }

}
